﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kugar.Core.BaseStruct;
using Kugar.Core.Web;
using Kugar.MVC.MobileUI.WeUI.Controllers;
using Kugar.MVC.MobileUI.WeUI.Demo.Models.Home;

namespace Kugar.MVC.MobileUI.WeUI.Demo.Controllers
{
    public class HomeController : MobileUIBaseController
    {
        public ActionResult Index()
        {
            ModelState.AddModelError("textbox","文本框错误");
            ModelState.AddModelError("ssss","多选款错误");
            ModelState.AddModelError("ssss2", "单选款错误");


            return View();
        }

        public ActionResult List()
        {
            var model = new Model_List();

            var lst=new List<SSSS>();

            for (int i = 0; i < 30; i++)
            {
                lst.Add(new SSSS()
                        {
                            Icon =
                                "https://www.wikihow.com/images_en/thumb/9/97/Insert-Spaces-in-HTML-Step-1.jpg/v4-728px-Insert-Spaces-in-HTML-Step-1.jpg.webp",
                            Title =i.ToString(),
                            Desc = i.ToString().PadLeft(8,i.ToString()[0])//,
                            //Url = "/"
                        });
            }

            model.List = lst.ToArray();

            return View(model);
        }

        public ActionResult FormTest()
        {
            return View();
        }

        public ActionResult ModalTest()
        {
            return View();
        }

        public ActionResult MsgPageTest()
        {
            return View();
        }

        public ActionResult TabbarTest()
        {
            var model = new Model_List();

            var lst = new List<SSSS>();

            for (int i = 0; i < 30; i++)
            {
                lst.Add(new SSSS()
                        {
                            Icon =
                                "https://www.wikihow.com/images_en/thumb/9/97/Insert-Spaces-in-HTML-Step-1.jpg/v4-728px-Insert-Spaces-in-HTML-Step-1.jpg.webp",
                            Title = i.ToString(),
                            Desc = i.ToString().PadLeft(8, i.ToString()[0])//,
                            //Url = "/"
                        });
            }

            model.List = lst.ToArray();

            return View(model);
        }

        public ActionResult NavbarTest()
        {
            var model = new Model_List();

            var lst = new List<SSSS>();

            for (int i = 0; i < 30; i++)
            {
                lst.Add(new SSSS()
                        {
                            Icon =
                                "https://www.wikihow.com/images_en/thumb/9/97/Insert-Spaces-in-HTML-Step-1.jpg/v4-728px-Insert-Spaces-in-HTML-Step-1.jpg.webp",
                            Title = i.ToString(),
                            Desc = i.ToString().PadLeft(8, i.ToString()[0])//,
                            //Url = "/"
                        });
            }

            model.List = lst.ToArray();

            return View(model);
        }

        public ActionResult PanelTest()
        {
            return View();
        }

        [HttpPost,ActionName("FileUpload")]
        public ActionResult FileUpload()
        {
            var file = Request.GetFile("nnnn");

            file.SaveAsEx("/uploads/images/" + file.FileName);


            return this.Json(new ResultReturn(true, new
                                                    {
                                                        ImageUrl = "/uploads/images/" + file.FileName
                                                    }),JsonRequestBehavior.AllowGet);
        }

        //多图的上传,由于表单定义的name不同,,所以测试的时候,需要分开两个action,实际可不用
        [HttpPost, ActionName("FileUpload2")] 
        public ActionResult FileUpload2()
        {
            var file = Request.GetFile("nn111");

            file.SaveAsEx("/uploads/images/" + file.FileName);


            return this.Json(new ResultReturn(true, new
                                                    {
                                                        ImageUrl = "/uploads/images/" + file.FileName
                                                    }), JsonRequestBehavior.AllowGet);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}